package com.sxf.controller.blog.admin;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.cache.CacheManager;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.context.request.ServletWebRequest;

import com.sxf.common.tools.WPConstants;
import com.sxf.util.CookieUtils;

@Controller
@RequestMapping("blog/logout")
public class LogoutController {
	@Resource(name = "memCacheManager")
	private CacheManager cm;

	/**
	 * 登出
	 * 
	 * @param web
	 * @param tourl
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("")
	public String logout(ServletWebRequest web,
			@RequestParam(required = false) String tourl) throws Exception {
		web.getRequest().getSession().invalidate();
		cm.getCache(WPConstants.SESSION_CACHE).evict(CookieUtils.USER_ID);
		CookieUtils.deleteCookie(web.getRequest(), web.getResponse(),
				CookieUtils.USER_ID);
		if (StringUtils.isNotBlank(tourl)) {
			return "redirect:" + tourl;
		}

		return "redirect:/blog/login";
	}

}
